<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%
  String path = request.getContextPath();
%>
<link href="<%=path%>/static/css/all.css?32239j" rel="stylesheet" type="text/css">
<!--[if IE]>
<script>
(function(){if(!/*@cc_on!@*/0)return;var e = "abbr,article,aside,audio,canvas,datalist,details,dialog,eventsource,figure,footer,header,hgroup,mark,menu,meter,nav,output,progress,section,time,video".split(','),i=e.length;while(i--){document.createElement(e[i])}})()
</script>
<![endif]-->
<script type="text/javascript" src="<%=path%>/static/js/jquery-3.3.1.min.js"></script>
<script type="text/javascript" src="<%=path%>/static/js/jquery.innerfade.js"></script>
<script type="text/javascript" src="<%=path%>/static/js/layui/layui.all.js"></script>
<script type="text/javascript">
	$(function(){
		$(".btnSwap").click(function(){
			var p = $(this).parents("dl");
			var txt = $(this).text();
			if(txt=="收起"){
				$(this).html($(this).data("title"));
				p.removeClass("open");
				p.addClass("off");
			}
			else{
				$(this).html("收起");
				$(this).data("title",txt);
				p.removeClass("off");
				p.addClass("open");
			}
			return false;
		});
	});
</script>
<jsp:include page="/web/inc/header"/>
<section>
<div class="wrap">
<div class="section">
    <article class="us" id="datalist">
      <div class="title">
      <img src="<%=path%>/static/images/${sessionScope.userinfo.headPic}" alt="用户昵称">
      <h1>用户信息</h1>
    </div>
    <div class="main">
      <dl class="off">
        <dt>昵称:</dt>
        <dd id="old-nickname">${sessionScope.userinfo.nickname}</dd>
        <dd><a href="#" class="btnSwap">修改</a></dd>
        <c:if test="${sessionScope.userinfo.userType.id eq 1}"><dd style="color: grey;font-weight: 700">普通用户</dd></c:if>
        <c:if test="${sessionScope.userinfo.userType.id eq 2}"><dd><img src="<%=path%>/static/images/vip.jpg" style="width: 55px;height: 26px"></dd></c:if>
        <c:if test="${sessionScope.userinfo.userType.id eq 3}"><dd><img src="<%=path%>/static/images/companys.jpg" style="width: 26px;height: 26px"></dd><dd style="color: green;font-weight: 700">${sessionScope.userinfo.companyApproval.companyName}</dd></c:if>


        <dd class="modify">
          <%--<form action="<%=path%>/web/userinfo/updateNickname" id="updateNickname" method="get">--%>
            <dl>
              <dt>输入新昵称</dt>
              <dd><input type="text" name="nickname" id="nickname" aria-label="输入新昵称" placeholder="输入新昵称" ></dd>
            </dl>
            <div class="submit">
              <input class="validate" id="update-nickname" type="button" value="确认修改">
            </div>
          <%--</form>--%>
        </dd>
      </dl>
      <dl class="off">
        <dt>邮箱:</dt>
        <dd id="email">
          <c:if test="${empty sessionScope.userinfo.email}" var="s">
             未绑定邮箱
          </c:if>
          <c:if test="${not s}">
            ${sessionScope.userinfo.email}
          </c:if>
        </dd>
        <dd>
            <a  href="#" class="btnSwap">添加/更换</a>
        </dd>
        <dd class="modify">
         <c:if test="${not empty sessionScope.userinfo.email}">
          <form action="<%=path%>/web/usercenter/updateEmail" method="get" id="update-email">
          <dl>
            <dt>原邮箱</dt>
            <dd><span>${sessionScope.userinfo.email} </span></dd>
            <dd><input class="validate" type="button" id="checkOldEmail" data-count="60" value="申请验证"></dd>
          </dl>
          <dl>
            <dt>原邮箱验证码</dt>
            <dd><input type="text" id="oldEmailCode" aria-label="原邮箱收到的验证码" placeholder="原邮箱收到的验证码" ></dd>
          </dl>
          <dl>
            <dt>新邮箱</dt>
            <dd><input type="text" id="newEmail" name="email" aria-label="输入新的邮箱地址" placeholder="输入新的邮箱地址" ></dd>
            <dd><input class="validate" type="button" id="updateEmail" data-count="60" disabled value="申请验证"></dd>
          </dl>
          <dl>
            <dt>新邮箱验证码</dt>
            <dd><input type="text" id="newEmailCode" aria-label="新邮箱收到的验证码" placeholder="新邮箱收到的验证码" ></dd>
          </dl>
          <div class="submit">
            <input class="validate" type="submit" name="submit" id="submitEmail" value="设置邮箱">
          </div>
          </form>
         </c:if>
        <c:if test="${empty sessionScope.userinfo.email}">
          <form action="<%=path%>/web/usercenter/updateEmail" method="get" id="add-email">
            <dl>
              <dt>添加邮箱</dt>
              <dd>
                <input type="text" name="email" id="new-email" aria-label="输入新的邮箱地址" placeholder="输入新的邮箱地址" >
              </dd>
              <dd>
                <input class="validate" type="button" id="check-email" data-count="60" value="申请验证">
              </dd>
            </dl>
            <dl>
              <dt>邮箱验证码</dt>
              <dd>
                <input type="text" id="email-code" aria-label="输入邮箱验证码" placeholder="输入邮箱验证码" >
              </dd>
            </dl>
            <div class="submit">
              <input class="validate" type="submit"  id="submit3" value="设置邮箱">
            </div>
          </form>
        </c:if>
        </dd>
      </dl>
      <dl class="off">
        <dt>手机:</dt>
        <dd id="phoneNumber"><c:if test="${empty sessionScope.userinfo.phoneNumber}" var="s">
          未绑定手机
        </c:if>
          <c:if test="${not s}">
            ${sessionScope.userinfo.phoneNumber}
          </c:if>
        </dd>
        <dd>
            <a  href="#" class="btnSwap">添加/更换</a>
        </dd>
        <dd class="modify">
          <c:if test="${not empty sessionScope.userinfo.phoneNumber}">
          <form action="<%=path%>/web/usercenter/updatePhone" method="get" id="rePhoneNumber">
          <dl>
            <dt>原号码</dt>
            <dd><span>${sessionScope.userinfo.phoneNumber} </span></dd>
            <dd>
              <input class="validate" type="button" name="phoneNumber" id="submit4" data-count="60" value="申请验证">
            </dd>
          </dl>
          <dl>
            <dt>原验证码</dt>
            <dd><input type="text"  id="oldPhoneCode" aria-label="原手机号短信验证码" placeholder="原手机号短信验证码" ></dd>
          </dl>
          <dl>
            <dt>新手机号</dt>
            <dd><input type="text" name="phoneNumber" id="newPhoneNumber" aria-label="输入新的手机号码" placeholder="输入新的手机号码" ></dd>
            <dd>
              <input class="validate" type="button" id="submit5" data-count="60" disabled value="申请验证">
            </dd>
          </dl>
          <dl>
            <dt>新验证码</dt>
            <dd><input type="text" id="newPhoneCode" aria-label="输入新手机短信验证码" placeholder="输入新手机短信验证码" ></dd>
          </dl>
          <div class="submit">
            <input class="validate" type="submit" value="设置手机号码">
          </div>
          </form>
          </c:if>
          <c:if test="${empty sessionScope.userinfo.phoneNumber}">
          <form action="<%=path%>/web/usercenter/updatePhone" method="get" id="addPhone">
          <dl>
            <dt>手机号码</dt>
            <dd><input type="text" name="phoneNumber" id="new-Phone" aria-label="输入新的手机号码" placeholder="输入新的手机号码" ></dd>
            <dd>
              <input class="validate" type="button" id="check-phone" data-count="60" value="申请验证">
            </dd>
          </dl>
          <dl>
            <dt>验证码</dt>
            <dd><input type="text" id="new-Code" aria-label="输入短信验证码" placeholder="输入短信验证码" ></dd>
          </dl>
          <div class="submit">
            <input class="validate" type="submit" id="setPhone" value="设置手机号码">
          </div>
          </form>
          </c:if>
        </dd>
        <dt>&nbsp;</dt>
      </dl>
      <dl class="off">
        <dt>头像:</dt>
        <dd><img src="<%=path%>/static/images/${sessionScope.userinfo.headPic }" alt="用户昵称" class="head-pic"></dd>
        <dd><a href="#" class="btnSwap">更换</a></dd>
        <dd class="modify">
          <form action="<%=path%>/web/usercenter/updateHeadPic" method="post" enctype="multipart/form-data">
          <dl>
            <dt>新头像</dt>
            <dd><input type="file" id="headPic" name="file" accept="image/*"></dd>
          </dl>
          <div class="submit">
            <input class="validate" id="update-head" type="submit" disabled value="更换头像">
          </div>
          </form>
        </dd>
      </dl>

      <dl class="off">
        <dt>个人认证:</dt>
          <c:if test="${sessionScope.userinfo.userType.id eq 3}" var="a"><dd><span style="color: green;font-weight: 700">您已经是企业认证用户</span></dd></c:if>
        <c:if test="${not a}">
          <dd>vip认证</dd>
          <dd><a href="#" class="btnSwap">认证</a></dd>
        </c:if>

          <dd class="modify">
          <c:if test="${sessionScope.userinfo.userType.id eq 1}">
            <c:if test="${sessionScope.userinfo.publishCount gt 10 and sessionScope.userinfo.answerCount gt 10}" var="flag">
              <c:if test="${sessionScope.userinfo.vipChecked eq null}">
              <span id="attestation"> <a href="javascript:void(0)" id="apply">您满足条件，点击申请VIP认证</a></span>
              </c:if>
              <c:if test="${sessionScope.userinfo.vipChecked eq 1}" var="f">
                vip认证正在审核中...
              </c:if>
              <c:if test="${sessionScope.userinfo.vipChecked eq 2}">
                <span id="again-attestation"> <a href="javascript:void(0)" id="again-apply">认证失败，点击重新申请认证</a></span>
              </c:if>
              <c:if test="${sessionScope.userinfo.vipChecked eq 0}">
                 vip认证通过
              </c:if>
            </c:if>
            <c:if test="${not flag}">
              您不满足申请VIP认证的资格(满足条件：发布文章数量十条以上并且回答数量十条以上)
            </c:if>
        </c:if>

        <c:if test="${sessionScope.userinfo.userType.id eq 2}">
          <span>已认证</span>
        </c:if>
        </dd>
      </dl>

      <dl class="off">
        <dt>代表单位:</dt>
        <c:if test="${sessionScope.userinfo.companyApproval.id eq 0}" var="flag">
          <dd>未认证</dd>
          <dd><a href="#" class="btnSwap">认证</a></dd>
        </c:if>
        <c:if test="${sessionScope.userinfo.companyApproval.id ne 0}">
            <c:if test="${sessionScope.userinfo.companyApproval.companyChecked eq 0}">
                <dd style="color: green;font-weight: 700" >企业审核通过</dd>
            </c:if>
            <c:if test="${sessionScope.userinfo.companyApproval.companyChecked eq 1}">
                <dd style="color: grey;font-weight: 700">正在审核中</dd>
            </c:if>
            <c:if test="${sessionScope.userinfo.companyApproval.companyChecked eq 2}">
                <dd style="color: red;font-weight: 700">企业审核不通过</dd>
            </c:if>

        </c:if>
        <dd class="modify">
          <form action="<%=path%>/web/usercenter/companyAuthenticat" method="post" enctype="multipart/form-data" id="company">
          <nav>
            <div class="seach">
                <select id="provinces">
                  <option>请选择省份</option>
                  <c:forEach items="${requestScope.provinces}" var="province">
                    <option value="${province.id}">${province.name}</option>
                  </c:forEach>
                </select>
                <select name="city.id" id="citys">
                  <option value="">请选择城市</option>
                </select>
            </div>
          </nav>
            <dl>
              <dt>代表企业名称</dt>
              <dd><input type="text" name="companyName" id="companyName"  required="required"/></dd>
            </dl>
          <dl>
            <dt>证明文件照片</dt>
            <dd><img class="license-pic"></dd>
            <dd><input type="file" name="companyPicture" id="companyPic" accept="image/*"></dd>
          </dl>
          <div class="submit">
            <input class="validate" type="submit" id="submit11" disabled value="提交认证">
          </div>
          </form>
        </dd>
      </dl>
      <dl class="off">
        <dt>密码管理:</dt>
        <dd><a  href="#" class="btnSwap">修改密码</a></dd>
        <dd class="modify">
          <form action="<%=path%>/web/usercenter/modPassword" method="get" id="tijiao">
          <dl>
            <dt>旧密码</dt>
            <dd><input id="oldpassword" type="password" name="old" aria-label="输入旧密码" placeholder="输入旧密码" ></dd>
          </dl>
          <dl>
            <dt>新密码</dt>
            <dd><input id="newpassword" type="password" name="password" aria-label="输入新密码" placeholder="输入新密码" ></dd>
          </dl>
          <dl>
            <dt>重复新密码</dt>
            <dd><input id="repassword" type="password" name="new" aria-label="再输入新密码" placeholder="再输入新密码" ></dd>
          </dl>
          <div class="submit">
            <input class="validate" type="button" id="anniu" value="更新密码">
          </div>
          </form>
        </dd>
      </dl>
      <dl>
        <dt>上次登录：</dt>
        <dd><span>时间：<fmt:formatDate value="${sessionScope.userinfo.lastLoginTime}" pattern="yyyy-MM-dd HH:mm"/> </span><span>ip:${sessionScope.userinfo.lastLoginIp}</span></dd>
      </dl>
      <dl>
        <dt>文章数量：</dt>
        <dd><span>${sessionScope.userinfo.publishCount}</span></dd>
      </dl>
      <dl>
        <dt>问答数量：</dt>
        <dd><span>提问：${sessionScope.userinfo.askCount} </span><span>答复：${sessionScope.userinfo.answerCount}</span></dd>
      </dl>
    </div>
  </article>
        <aside>
      <div class="top">
        <h3>用户中心</h3>
      </div>
      <ul>
        <li><a href="<%=path%>/web/usercenter/usPassport" style="font-weight: 900">用户信息</a></li>
        <li><a href="<%=path%>/web/usercenter/usDatelist">我提供的垃圾</a></li>
        <li><a href="<%=path%>/web/usercenter/usTexture">我提供的材质</a></li>
        <li><a href="<%=path%>/web/usercenter/usArticle">我的文章</a></li>
        <li><a href="<%=path%>/web/usercenter/usQuestions">我的提问</a></li>
        <li><a href="<%=path%>/web/usercenter/usAnswers">我的回答</a></li>
        <li><a href="<%=path%>/web/usercenter/usCollect">我的收藏</a></li>
      </ul>
    </aside></div>
</div>
</div>
</section>
<jsp:include page="/web/inc/footer"/>
<script>
  $(function () {
    $("#update-nickname").click(updateNickname)

  //判断昵称是否重复修改昵称
  function updateNickname() {
     var nickname = $("#nickname").val();
     var regExp=/(^[\u4e00-\u9fa5]{2,8}$)|(^[a-zA-Z]{4,16}$)/;
     if(regExp.test(nickname)){
       $.get("<%=path%>/web/usercenter/checkNickname",
               {nickname:nickname},
               function (data) {
                 if(data=="1"){
                   layer.msg("该昵称已存在，请重新输入",{icon:5})
                 }
                 else {
                   $("#old-nickname").html(nickname);
                   layer.msg("昵称修改成功",{icon:1})
                 /* $("#updateNickname").submit();*/
                 }
               }
       )}
     else {
       layer.msg("昵称格式不正确",{icon:5})
     }
  }
//原邮箱发送验证码
    var code="";
    var newCode="";
    var code2="";
    var code3="";
    var code4="";
    var code5="";
   $("#checkOldEmail").click(function () {
     var email = $("#email").html();
     $.get("<%=path%>/web/userinfo/sendEmailCode",
     {email:email},
      function (data) {
        code=data;
      })
     $("#checkOldEmail").prop("disabled", true);
     var count;
     var settime;

     function countdown() {
       count = parseInt($("#checkOldEmail").data("count"));
       count = count - 1;
       $("#checkOldEmail").val(count + "秒后获取");
       $("#checkOldEmail").data("count", count);
       settime = setTimeout(countdown, 1000);

       if (count == 0) {
         clearTimeout(settime);
         $("#checkOldEmail").val("重新获取");
         $("#checkOldEmail").data("count", "60");
         $("#checkOldEmail").prop("disabled", false);
       }
     }
     countdown();
   })
//验证原邮箱验证码

    $("#oldEmailCode").blur(getEmailCode)

   function getEmailCode() {

      var f = false;
      var code1 = $("#oldEmailCode").val();
      if (code1!=code){
        layer.msg("验证码不正确",{icon:2})
        f=false;
      }
      else {
        f=true;
      }
      return f;
  }
  //判断新邮箱格式
  $("#newEmail").keyup(function () {
    var newEmail = $("#newEmail").val();
    var regExp = /^[A-Za-z0-9\u4e00-\u9fa5]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
    if(regExp.test(newEmail)){
      $("#updateEmail").prop("disabled", false);
    }
    else {
      $("#updateEmail").prop("disabled", true);
    }
  })
  //点击判断邮箱是否重复
  $("#updateEmail").click(function () {
    var email = $("#newEmail").val();
    $.get("<%=path%>/web/userinfo/checkEmail",
            {email:email},
            function (data) {
              if(data=="1"){
                layer.msg("该邮箱已注册",{icon:2})
              }
              else {
                  getCode()
              }
            })
    //新邮箱发送邮件
    function getCode(){
      var email = $("#newEmail").val();
      $.get("<%=path%>/web/userinfo/sendEmailCode",
              {email:email},
              function (data) {
                newCode = data;
              })
      $("#updateEmail").prop("disabled", true);
      var count;
      var settime;

      function countdown() {
        count = parseInt($("#updateEmail").data("count"));
        count = count - 1;
        $("#updateEmail").val(count + "秒后获取");
        $("#updateEmail").data("count", count);
        settime = setTimeout(countdown, 1000);

        if (count == 0) {
          clearTimeout(settime);
          $("#updateEmail").val("重新获取");
          $("#updateEmail").data("count", "60");
          $("#updateEmail").prop("disabled", false);
        }
      }
      countdown();
    }
  })
  //判断新邮箱验证码

    $("#submitEmail").click(checkNewCode)

  function checkNewCode() {
    var f = false;
    var emailCode = $("#newEmailCode").val();
    if(emailCode==newCode){
      f=true;
    }
    else{
      layer.msg("验证码错误",{icon:2})
      f=false;
    }
    return f;
  }
  //修改邮箱表单提交
    $("#update-email").submit(function () {
      var flagGetEmailCode = getEmailCode();
      var flagCheckNewCode = checkNewCode();
      return flagCheckNewCode&&flagGetEmailCode;
    })
    //绑定邮箱
    $("#check-email").click(function () {
      var email = $("#new-email").val();
      var regExp = /^[A-Za-z0-9\u4e00-\u9fa5]+@[a-zA-Z0-9_-]+(\.[a-zA-Z0-9_-]+)+$/;
      if(regExp.test(email)){
      $.get("<%=path%>/web/userinfo/checkEmail",
              {email:email},
              function (data) {
                if(data=="1"){
                  layer.msg("该邮箱已被注册",{icon:2})
                }
                else{
                  getNewCode();
                }
              })
    }
      else {
        layer.msg("邮箱格式不正确",{ico: 2})
      }
   })
    //新邮箱发送验证码
    function getNewCode(){
      var email = $("#new-email").val();
      $.get("<%=path%>/web/userinfo/sendEmailCode",
              {email:email},
              function (data) {
                code2 = data;
              })
      $("#check-email").prop("disabled", true);
      var count;
      var settime;

      function countdown() {
        count = parseInt($("#check-email").data("count"));
        count = count - 1;
        $("#check-email").val(count + "秒后获取");
        $("#check-email").data("count", count);
        settime = setTimeout(countdown, 1000);

        if (count == 0) {
          clearTimeout(settime);
          $("#check-email").val("重新获取");
          $("#check-email").data("count", "60");
          $("#check-email").prop("disabled", false);
        }
      }
      countdown();
    }
    //判断新邮箱验证
    $("#submit3").click(sendCode)
    function sendCode() {
      var f=false;
      var code=$("#email-code").val();
      if(code==code2)
      {
        f=true;
      }
      else{
        layer.msg("验证码不正确",{icon:2})
        f=false;
      }
      return f;
    }
    //添加新邮箱表单验证
    $("#add-email").submit(function () {
      var flagsendCode = sendCode();
      return flagsendCode;
    })
    //发送原手机验证码
    $("#submit4").click(function () {
      var phoneNumber = $("#phoneNumber").html();
      $.get("<%=path%>/web/userinfo/sendPhoneCode",
              {phoneNumber:phoneNumber},
              function (data) {
                code3=data;
              })
      $("#submit4").prop("disabled", true);
      var count;
      var settime;

      function countdown() {
        count = parseInt($("#submit4").data("count"));
        count = count - 1;
        $("#submit4").val(count + "秒后获取");
        $("#submit4").data("count", count);
        settime = setTimeout(countdown, 1000);

        if (count == 0) {
          clearTimeout(settime);
          $("#submit4").val("重新获取");
          $("#submit4").data("count", "60");
          $("#submit4").prop("disabled", false);
        }
      }
      countdown();
    })
    //判断原手机验证码
    $("#oldPhoneCode").blur(getPhoneCode)
    function getPhoneCode() {
      var f = false;
      var code = $("#oldPhoneCode").val();
      if (code!=code3){
        layer.msg("验证码不正确",{icon:2})
        f=false;
      }
      else {
        f=true;
      }
      return f;
    }
    //验证新手机号
    $("#newPhoneNumber").keyup(function () {
      var phoneNumber = $("#newPhoneNumber").val();
      var regExp = /^[1]([3-9])[0-9]{9}$/;
      if(regExp.test(phoneNumber)){
        $("#submit5").prop("disabled", false);
      }
      else {
        $("#submit5").prop("disabled", true);
      }
    })
    //点击判断手机是否重复
    $("#submit5").click(function () {
      var phoneNumber = $("#newPhoneNumber").val();
      $.get("<%=path%>/web/userinfo/checkPhone",
              {phoneNumber:phoneNumber},
              function (data) {
                if(data=="1"){
                  layer.msg("该手机已注册",{icon:2})
                }
                else {
                  getNewPhoneCode()
                }
              })
      //新手机发送验证码
      function getNewPhoneCode(){
        var phoneNumber = $("#newPhoneNumber").val();
        $.get("<%=path%>/web/userinfo/sendPhoneCode",
                {phoneNumber:phoneNumber},
                function (data) {
                  code4 = data;
                })
        $("#submit5").prop("disabled", true);
        var count;
        var settime;

        function countdown() {
          count = parseInt($("#submit5").data("count"));
          count = count - 1;
          $("#submit5").val(count + "秒后获取");
          $("#submit5").data("count", count);
          settime = setTimeout(countdown, 1000);

          if (count == 0) {
            clearTimeout(settime);
            $("#submit5").val("重新获取");
            $("#submit5").data("count", "60");
            $("#submit5").prop("disabled", false);
          }
        }
        countdown();
      }
    })
    //判断新手机验证
    $("#submit5").click(sendPhoneCode)
    function sendPhoneCode() {
      var f=false;
      var code=$("#newPhoneCode").val();
      if(code==code4)
      {
        f=true;
      }
      else{
        layer.msg("验证码不正确",{icon:2})
        f=false;
      }
      return f;
    }
    //更换手机表单验证
    $("#rePhoneNumber").submit(function () {
      var flagPhoneCode = getPhoneCode();
      var flagsendPhoneCode = sendPhoneCode();
      return flagPhoneCode&&flagsendPhoneCode;
    })
    //添加手机
    $("#check-phone").click(function () {
      var phoneNumber = $("#new-Phone").val();
      var regExp = /^[1]([3-9])[0-9]{9}$/;
      if(regExp.test(phoneNumber)){
        $.get("<%=path%>/web/userinfo/checkPhone",
                {phoneNumber:phoneNumber},
                function (data) {
                  if(data=="1"){
                    layer.msg("该手机已被注册",{icon:2})
                  }
                  else{
                    getNewPhone();
                  }
                })
      }
      else {
        layer.msg("请输入正确的手机号",{ico: 2})
      }
    })
    //新手机发送验证码
    function getNewPhone(){
      var phoneNumber = $("#new-Phone").val();
      $.get("<%=path%>/web/userinfo/sendPhoneCode",
              {phoneNumber:phoneNumber},
              function (data) {
                code5 = data;
              })
      $("#check-phone").prop("disabled", true);
      var count;
      var settime;

      function countdown() {
        count = parseInt($("#check-phone").data("count"));
        count = count - 1;
        $("#check-phone").val(count + "秒后获取");
        $("#check-phone").data("count", count);
        settime = setTimeout(countdown, 1000);

        if (count == 0) {
          clearTimeout(settime);
          $("#check-phone").val("重新获取");
          $("#check-phone").data("count", "60");
          $("#check-phone").prop("disabled", false);
        }
      }
      countdown();
    }
    //判断新手机验证
    $("#setPhone").click(sendPhoneNumberCode)
    function sendPhoneNumberCode() {
      var f=false;
      var code=$("#new-Code").val();
      if(code==code5)
      {
        f=true;
      }
      else{
        layer.msg("验证码不正确",{icon:2})
        f=false;
      }
      return f;
    }
    //添加新邮箱表单验证
    $("#addPhone").submit(function () {
      var flagsendPhoneNumberCode = sendPhoneNumberCode();
      return flagsendPhoneNumberCode;
    })
    //修改头像
    function show () {
      var src = window.URL.createObjectURL(this.files[0]);

      var filePath = $("#headPic").val();         //获取到input的value，里面是文件的路径
      var fileFormat = filePath.substring(filePath.lastIndexOf(".")).toLowerCase();
      if (!fileFormat.match(/.png|.jpg|.jpeg|.bmp/)) {
        alert('上传错误,文件格式必须为：png/jpg/jpeg');
      }else{
        $("#update-head").attr("disabled",false);
        $("#update-head").css("background-color","#f88600");
        $("#update-head").css("color","white");
        $('.head-pic').attr('src', src);
      }
   }
    $("#headPic").change(show);


    $("#anniu").click(function () {
      //判断原密码
      var f = true;
      var password=$("#oldpassword").val();
      $.ajaxSettings.async=false;
      $.get("<%=path%>/web/usercenter/changePassword",
              {password:password},
              function (data) {
                if(data=="0")
                {
                  layer.msg("密码不正确",{icon:5})
                  f = false;
                }
              });
      if(f==false){
        return;
      }
      //验证新密码
      var newpassword=$("#newpassword").val();
      var regExp = /^(?![A-Z]+$)(?![a-z]+$)(?!\d+$)\S{8,16}$/;
      if(!regExp.test(newpassword)) {
        layer.msg("密码长度不低于8位，至少含有一个数字和一个字母",{icon: 5})
        return;
      }
      //验证第二次输入的新密码
      var repassword=$("#repassword").val();
      if(repassword!=newpassword)
      {
        layer.msg("两次密码不一致！",{icon:5})
        return;
      }

      $("#tijiao").submit()
    });



    //点击申请VIP认证
    $("#apply").click(function () {
      $.get("<%=path%>/web/usercenter/checkVIP",
        function () {
          layer.msg("申请成功",{icon:6})
          $("#attestation").html("vip认证正在审核中...")
          $("#attestation").css("color","gray")
        }
      )
    });
    //失败再次认证
    $("#again-apply").click(function () {
      $.get("<%=path%>/web/usercenter/checkVIP",
              function () {
                layer.msg("再次申请成功",{icon:6})
                $("#again-attestation").html("vip认证正在审核中...")
                $("#again-attestation").css("color","gray")
              }
      )
    })
    //省市联动
    $("#provinces").change(changeCity);
        function changeCity() {
        var pid = $(this).val();
        $("#citys").empty();
        $.get("<%=path%>/web/city/findCities",
                {pid:pid},
                function (data) {
                  $("#citys").append("<option value=''>请选择城市</option>");
                  $(data).each(function () {
                    $("#citys").append("<option value="+this.id+">"+this.name+"</option>");
                  })
                });
    }
    //上传企业图片
    function companyshow () {
      var src = window.URL.createObjectURL(this.files[0]);

      var filePath = $("#companyPic").val();         //获取到input的value，里面是文件的路径
      var fileFormat = filePath.substring(filePath.lastIndexOf(".")).toLowerCase();
      if (!fileFormat.match(/.png|.jpg|.jpeg|.bmp/)) {
        alert('上传错误,文件格式必须为：png/jpg/jpeg');
      }else{
        $("#submit11").attr("disabled",false);
        $("#submit11").css("background-color","#f88600");
        $("#submit11").css("color","white");
        $('.license-pic').attr('src', src);
      }
    }
    $("#companyPic").change(companyshow)

    //判断企业是否被认证
    function checkCertificate() {
      var companyName = $("#companyName").val();
      var flag = false;
      $.ajax({
              url:"<%=path%>/web/usercenter/findCompanyName",
              data:{companyName:companyName},
              type:"get",
              async:false,
              success:function (data) {
                if(data=="1")
                {
                  layer.msg("该公司/企业/机构已被认证",{icon:2})
                  flag = false;
                }
                if(data=="0")
                {
                   flag=true;
                }
              }});
      return flag;
    }

    //判断城市是否已选择
    function checkCity() {
      var checkCity = $("#citys").val();
      if (checkCity==""){
        layer.msg("请选择城市",{icon:2})
        return false;
      }
      else {
        return true;
      }
    }

    //判断是否上传图片
    function checkPic() {
      var checkPic = $("#companyPic").val();
      if (checkPic==""){
        return false;
      }
      else {
        return true;
      }
    }
    //企业认证表单提交
    $("#company").submit(function () {
      var flag1 = checkCertificate();
      var  flag2 = checkCity();
      var  flag3 = checkPic();
      return flag1&&flag2&&flag3;
    })

  })
</script>

